package io.kimmking.rpcfx.client;


import com.alibaba.fastjson.parser.ParserConfig;
import io.kimmking.rpcfx.api.Filter;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.stereotype.Component;

@Component
public final class RpcfxCglib {

    static {
        ParserConfig.getGlobalInstance().addAccept("io.kimmking");
    }


    public static <T> T create(final Class<T> serviceClass, final String url, Filter... filters) {
        Enhancer enhancer = new Enhancer();
        //设置目标类的字节码文件
        enhancer.setSuperclass(serviceClass);
        //设置回调函数
        enhancer.setCallback(new CustomInterceptor(serviceClass, url, filters));
        //这里的creat方法就是正式创建代理类
        return  (T) enhancer.create();
    }


}
